/*
 * 
 *  This file is part of Sourceprojects.org Lycia Copyright 2010 noctarius
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */
package org.sourceprojects.lycia.test.annotated;

import javax.xml.namespace.QName;

import org.junit.Test;
import org.sourceprojects.lycia.DefinitionBuilder;
import org.sourceprojects.lycia.LyciaParser;
import org.sourceprojects.lycia.ParserContext;
import org.sourceprojects.lycia.QualifiedName;
import org.sourceprojects.lycia.exceptions.LyciaParsingException;
import org.sourceprojects.lycia.fluent.FluentBuilder;
import org.sourceprojects.lycia.test.TestCaseUtilities;
import org.w3c.dom.Element;

import static org.sourceprojects.lycia.fluent.FluentBuilder.*;
import static org.junit.Assert.*;

public class BaseInjectionTestCase {

	private static final String XML_SIMPLE = TestCaseUtilities.XML_HEADER
			+ "<test><testcase-simple /></test>";

	private final Object contextObject = new Object();

	@Test
	public void testBaseInjectionNullUnaware() throws LyciaParsingException {
		FluentBuilder<Object> builder = prepare();
		LyciaParser<Object> parser = builder.configure(nullAware(false),
				contextObject(contextObject)).parser(
				tag("testcase-simple", method("baseInjection", this,
						Element.class, String.class, QName.class,
						QualifiedName.class, ParserContext.class,
						DefinitionBuilder.class))).build();

		parser.parse(XML_SIMPLE);
	}

	@Test
	public void testBaseInjectionNullAware() throws LyciaParsingException {
		FluentBuilder<Object> builder = prepare();
		LyciaParser<Object> parser = builder.configure(
				contextObject(contextObject)).parser(
				tag("testcase-simple", method("baseInjection", this,
						Element.class, String.class, QName.class,
						QualifiedName.class, ParserContext.class,
						DefinitionBuilder.class))).build();

		parser.parse(XML_SIMPLE);
	}

	public void baseInjection(Element element, String localName, QName qName,
			QualifiedName qualifiedName, ParserContext<Object> parserContext,
			DefinitionBuilder definitionBuilder) {

		assertNotNull(element);
		assertEquals("testcase-simple", element.getLocalName());

		assertNotNull(localName);
		assertEquals("testcase-simple", localName);

		assertNotNull(qName);
		assertEquals("testcase-simple", qName.getLocalPart());

		assertNotNull(qualifiedName);
		assertEquals("testcase-simple", qualifiedName.getLocalPart());

		assertNotNull(parserContext);
		assertEquals(contextObject, parserContext.getContextObject());

		assertNotNull(definitionBuilder);
	}

}
